<?php

class IndexController extends ControllerBase
{
    public function initialize()
    {
        $this->tag->setTitle('欢迎');
        parent::initialize();
    }

    public function indexAction()
    {
        if (!$this->request->isPost()) {
            $this->flash->notice('首页测试，请不要泄露个人信息.');
        }
    }

	public function rolesAction()
	{
		$acl = new AclDatabase(array(
			'db' => $this->db,
			'roles' => 'roles',
			'rolesInherits' => 'roles_inherits',
			'resources' => 'resources',
			'resourcesAccesses' => 'resources_accesses',
			'accessList' => 'access_list',
		));


		$acl->setDefaultAction(Phalcon\Acl::DENY);

		//You can add roles/resources/accesses to list or insert them directly in the tables

		//Add roles
		$acl->addRole(new Phalcon\Acl\Role('Admins'));

		//Create the resource with its accesses
		$acl->addResource('Products', array('insert', 'update', 'delete'));

		//Allow Admins to insert products
		$acl->allow('Admins', 'Products', 'insert');

		//Do Admins are allowed to insert Products?
		var_dump($acl->isAllowed('Admins', 'Products', 'update'));
		var_dump($acl->isAllowed('Admins', 'Products', 'insert'));

	}
}

